package com.ftx.controller.queue;

import java.util.Deque;
import java.util.LinkedList;

/**
 * Created by fengtingxin on 2020/6/30.
 */
public class CQueue {

    //stack1 只负责增加元素
    Deque<Integer> stack1;

    //负责删除的元素
    Deque<Integer> stack2;


    public CQueue() {
        stack1 = new LinkedList<>();
        stack2 = new LinkedList<>();

    }

    //增加元素
    public void appendTail(int value) {
        stack1.push(value);
    }

    /**
     * 删除头
     * @return
     */
    public int deleteHead() {
        stack2.clear();
        if (stack2.isEmpty()){
            while (!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
        }
        if (stack2.isEmpty()) {
            return -1;
        } else {
            int deleteItem = stack2.pop();
            return deleteItem;
        }

    }
}
